import { useState } from "react"

import http from "../../../helper/request"
import { IQueryListParams, IResponseItem, IResponseSummary } from "./types"

const useApi = () => {
	const [loading, setLoading] = useState(false)

	async function generalHttp<T>(url: string, body: object | undefined, config: object = {}) {
		setLoading(true)
		let ret = await http.post<T>(url, body, config)
		setLoading(false)
		return ret
	}

	const getTableData = (body: IQueryListParams) =>
		generalHttp<Business.TableResourceType<IResponseItem>>("/report/proxy/income/report/list", body)

	const getTotalSummary = (body: IQueryListParams) => generalHttp<IResponseSummary>("/report/proxy/income/report/summary", body)

	return {
		loading,
		getTableData,
		getTotalSummary
	}
}

export default useApi
